package com.dk.controller;

import com.dk.em.Result;
import com.dk.pojo.SysAutoCodePart;
import com.dk.pojo.SysAutoCodeRule;
import com.dk.service.RuleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("coderule")
@Api(tags = "编码规则crud")
@RefreshScope    //开启热更新
public class RuleCodeController {

    @Autowired
    private RuleService ruleService;

    /*增加*/
    @PostMapping
    @ApiOperation("增加规则")
    public Result insertcoderule(@RequestBody SysAutoCodeRule rule){
        ruleService.insertcoderule(rule);
        return Result.OK();
    }

    /*查询*/
    @GetMapping
    @ApiOperation("查询规则")
    public Result getcoderule(){
        List<SysAutoCodeRule> rule = ruleService.getcoderule();
        return Result.OK().setData(rule);
    }

    /*id删除*/
    @DeleteMapping
    @ApiOperation("根据id删除")
    @ApiImplicitParam(value = "ruleId",name = "规则id")
    public Result deletecoderule(Long ruleId){
        ruleService.deleteByRuleId(ruleId);
        return Result.OK();
    }

    /*批量删除*/
    @DeleteMapping("deleteAllRuleId")
    @ApiOperation("批量删除")
    public Result deleteAllRuleId(@RequestBody List<String> ruleIds){
        ruleService.deleteAllRuleId(ruleIds);
        return Result.OK();
    }

    /*修改*/
    @PutMapping
    @ApiOperation("修改")
    public Result updateRule(@RequestBody SysAutoCodeRule rule){
        ruleService.updateRule(rule);
        return Result.OK();
    }

    /*List<SysAutoCodePart> selectByExample(SysAutoCodePartExample example);*/
    @GetMapping("selectByExample")
    public List<SysAutoCodeRule> selectByExample(String codename){
        List<SysAutoCodeRule> partList = ruleService.selectByExample(codename);
        return partList;
    }
}
